Trò chơi đua xe động vật trong UNITY Engine
114.926 lượt xem;
- TaskBar.cs
- GameScreen /
- AnimalRacing /
- Scripts /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 namespace GamePlay
5 {
6 public class TaskBar : MonoBehaviour
7 {
8 public GameObject rankLabel;
9 public GameObject goldLabel;
10 public GameObject timeLabel;
11 public GameObject scoreLabel;
12 public Dots dots;
13
14 private BitmapFont rankFont;
15 private BitmapFont fontGold;
16 private BitmapFont fontTime;
17 private BitmapFont fontScore;
18
19 private int gold;
20 private int score;
21 private float time;
22
23 public void Start()
24 {
25 rankFont = new BitmapFont("Fonts/font_rank", "Fonts/font_rank_xml", rankLabel);
26
27 fontTime = new BitmapFont("Fonts/font_time", "Fonts/font_time_xml", timeLabel);
28 fontGold = new BitmapFont(fontTime, goldLabel);
29 fontScore = new BitmapFont(fontTime, scoreLabel);
30 }
31
32 public void Update()
33 {
34 rankFont.setText(dots.getRankPlayer() + "", 0, 0, "GUI", "GUI");
35 fontTime.setText(((int)(time * 100)) / 100.0f + "", 0, 0, "GUI", "GUI");
36 fontGold.setText(gold + "", 0, 0, "GUI", "GUI");
37 fontScore.setText(score + "", 0, 0, "GUI", "GUI");
38 }
39
40 public int getRankPlayer()
41 {
42 return dots.getRankPlayer();
43 }
44
45 public void setParams(int gold, int score, float time)
46 {
47 this.gold = gold;
48 this.score = score;
49 this.time = time;
50 }
51 }
52 }
2 using System.Collections;
3
4 namespace GamePlay
5 {
6 public class TaskBar : MonoBehaviour
7 {
8 public GameObject rankLabel;
9 public GameObject goldLabel;
10 public GameObject timeLabel;
11 public GameObject scoreLabel;
12 public Dots dots;
13
14 private BitmapFont rankFont;
15 private BitmapFont fontGold;
16 private BitmapFont fontTime;
17 private BitmapFont fontScore;
18
19 private int gold;
20 private int score;
21 private float time;
22
23 public void Start()
24 {
25 rankFont = new BitmapFont("Fonts/font_rank", "Fonts/font_rank_xml", rankLabel);
26
27 fontTime = new BitmapFont("Fonts/font_time", "Fonts/font_time_xml", timeLabel);
28 fontGold = new BitmapFont(fontTime, goldLabel);
29 fontScore = new BitmapFont(fontTime, scoreLabel);
30 }
31
32 public void Update()
33 {
34 rankFont.setText(dots.getRankPlayer() + "", 0, 0, "GUI", "GUI");
35 fontTime.setText(((int)(time * 100)) / 100.0f + "", 0, 0, "GUI", "GUI");
36 fontGold.setText(gold + "", 0, 0, "GUI", "GUI");
37 fontScore.setText(score + "", 0, 0, "GUI", "GUI");
38 }
39
40 public int getRankPlayer()
41 {
42 return dots.getRankPlayer();
43 }
44
45 public void setParams(int gold, int score, float time)
46 {
47 this.gold = gold;
48 this.score = score;
49 this.time = time;
50 }
51 }
52 }